/*
 * @Author: zhangshu
 * @email: shiliang.zhang@tuya.com
 * @LastEditors: Please set LastEditors
 * @file name: app_ias_zone.h
 * @Description: 
 * @Copyright: HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
 * @Company: http://www.tuya.com
 * @Date: 2022-02-08
 * @LastEditTime: 2022-02-08
 */
#ifndef __APP_IAS_ZONE_H__
#define __APP_IAS_ZONE_H__

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

#include "app_common.h"

// ias zone bit enum
typedef enum {
  IAS_ZONE_STATUS_BIT_ALARM_1            = 0x0001,
  IAS_ZONE_STATUS_BIT_ALARM_2            = 0x0002,
  IAS_ZONE_STATUS_BIT_TAMPER             = 0x0004,
  IAS_ZONE_STATUS_BIT_BATTERY_LOW        = 0x0008,
  IAS_ZONE_STATUS_BIT_SUPERVISION_NOTIFY = 0x0010,
  IAS_ZONE_STATUS_BIT_RESTORE_NOTIFY     = 0x0020,
  IAS_ZONE_STATUS_BIT_TROUBLE            = 0x0040,
  IAS_ZONE_STATUS_BIT_AC_MAIN_FAULT      = 0x0080,
  IAS_ZONE_STATUS_BIT_SENSOR_TEST        = 0x0100,
  IAS_ZONE_STATUS_BIT_BATTERY_DEFECT     = 0x0200,
} ZONE_STATUS_BIT_E;

/**
 * @description: ias zone init after preheat time delay, gpio state may not stable during the preheat time
 * @param[in] none
 * @return: none
 */
VOID_T app_zone_control_preheat_init(VOID_T);

/**
 * @description: ias zone cluster command receive handler
 * @param[in] cmd: command id
 * @param[in] payload: command payload
 * @param[in] cmd: command payload length
 * @param[in] cmd_type: command type, single or group
 * @return: OPERATE_RET, success when OPRT_OK, or else
 */
OPERATE_RET ias_zone_cluster_server_command_handler(UCHAR_T cmd, UINT8_T *payload, UINT8_T payload_len, ZIGBEE_CMD_E cmd_type);

/**
 * @description: ias zone cluster write cie attribute receive handler
 * @param[in] none
 * @return: none
 */
VOID_T ias_zone_cie_address_write_callback(VOID_T);

/**
 * @description: set ias zone status bitmaps
 * @param [in] bit: zone status bit, please refer to ZONE_STATUS_BIT_E
 * @param [in] report: TRUE when need report, FALSE when not
 * @param [in] delay_ms: delay time in ms
 * @return: none
 */
VOID_T ias_zone_status_bit_set_with_report(ZONE_STATUS_BIT_E bit, BOOL_T report, UINT16_T delay_ms);

/**
 * @description: clear ias zone status bitmaps
 * @param [in] bit: zone status bit, please refer to ZONE_STATUS_BIT_E
 * @param [in] report: TRUE when need report, FALSE when not
 * @param [in] delay_ms: delay time in ms
 * @return: none
 */
VOID_T ias_zone_status_bit_clear_with_report(ZONE_STATUS_BIT_E bit, BOOL_T report, UINT16_T delay_ms);

/**
 * @description: obtain device enroll state, enroll or not
 * @param[in] none
 * @return: TRUE when device already enrolled, FALSE when device in unenroll state
 */
BOOL_T is_device_enrolled(VOID_T);

/**
 * @description: device in alarm state or not
 * @param[in] none
 * @return: TRUE when device in alarm state, FALSE when device normal
 */
BOOL_T is_in_alarm_state(VOID_T);

/**
 * @description: device in alarm state or not
 * @param[in] none
 * @return: TRUE when device in alarm state, FALSE when device normal
 */
VOID_T ias_zone_unenroll(VOID_T);

#ifdef __cplusplus
}
#endif

#endif /* __cplusplus */

